;;;
;;;
;;;	Author:
;;;		Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;	http://www.paracadd.com
;;;	All rights reserved.
;;;
;;;	Copyright:  
;;;	   Edited:  
(defun c:sfill ()
  (if c:mklayr nil (load "mklayr" "\nFile MKLAYR.LSP not found! "))
  (princ "\nSelect lines or polylines to fill: ")
  (setq fillents (ssget '((-4 . "<OR")(0 . "LINE")(-4 . "<AND")(-4 . "<OR")(70 . 1)(70 . 129)(-4 . "OR>")(0 . "POLYLINE")(-4 . "AND>")(-4 . "OR>"))))
  (setq fillpt_lst nil)
  (setq ss_Step 0)
  (setq ss_count (sslength fillents))
  (while (< ss_step ss_count)
    (setq curfillent (entget (ssname fillents ss_step)))
    (cond
      ((eq(cdr(assoc 0 curfillent))"LINE")
         (if fillpt_lst
	   (setq fillpt_lst (append fillpt_lst (list (cdr(assoc 10 curfillent))(cdr(assoc 11 curfillent)))))
	   (setq fillpt_lst (list (cdr(assoc 10 curfillent))(cdr(assoc 11 curfillent))))
	 )
      )
      ((eq(cdr(assoc 0 curfillent))"POLYLINE")
         (setq fillpt_lst (list(cdr(assoc 10 curfillent))))
         (while (not(eq(cdr(assoc 0 (setq curfillent(entget(entnext(cdr(assoc -1 curfillent)))))))"SEQEND"))
	   (setq fillpt_lst (append fillpt_lst (list(cdr(assoc 10 curfillent)))))
	 )
         (if (eq(length fillpt_lst)2)
	   (progn
	     (setq ss_step (1+ ss_step))
	     (setq curfillent (entget (ssname fillents ss_step)))
             (while (not(eq(cdr(assoc 0 (setq curfillent(entget(entnext(cdr(assoc -1 curfillent)))))))"SEQEND"))
	       (setq fillpt_lst (append fillpt_lst (list(cdr(assoc 10 curfillent)))))
	     )
	   )
	 )
      )
    )
    (setq ss_step (1+ ss_step))
  )
  (if (equal '(0.0 0.0 0.0) (car fillpt_lst))
    (setq fillpt_lst (cdr fillpt_lst))
  )
;;;  (princ fillpt_lst)
  (cond
    ((equal (angle (nth 0 fillpt_lst)(nth 1 fillpt_lst))
           (angle (nth 2 fillpt_lst)(nth 3 fillpt_lst))1)
     (c:svlayr)
     (command ".layer" "m" "SOLID-BOX" "c" 254 "SOLID-BOX" "")
     (command ".pline" (nth 0 fillpt_lst)(nth 1 fillpt_lst)(nth 3 fillpt_lst)(nth 2 fillpt_lst)(nth 0 fillpt_lst)"c")
     (command ".bhatch" "p" "ansi31" 2 (*(/(angle(nth 0 fillpt_lst)(nth 1 fillpt_lst))pi)180) "s" "l" "" "")
     (c:rslayr)
;;;     (princ "\nAngle matches")
    )
    ((equal (angle (nth 0 fillpt_lst)(nth 1 fillpt_lst))
           (angle (nth 3 fillpt_lst)(nth 2 fillpt_lst))1)
     (c:svlayr)
     (command ".layer" "m" "SOLID-BOX" "c" 254 "SOLID-BOX" "")
     (command ".pline" (nth 0 fillpt_lst)(nth 1 fillpt_lst)(nth 2 fillpt_lst)(nth 3 fillpt_lst)(nth 0 fillpt_lst)"c")
     (command ".bhatch" "p" "ansi31" 2 (*(/(angle(nth 0 fillpt_lst)(nth 1 fillpt_lst))pi)180) "s" "l" "" "")
     (c:rslayr)
;;;     (princ "\nReverse angle matches")
    )
    (T (princ "\nSides are not parallel, cannot determine correct order of points! "))
  )
  (princ)
)